const EnterService = require("../service/enter.service")
const ItemService = require("../service/item.service")

class EnterController {
    async create(ctx,next) {
        const { name,number,volume,categoryId,stashId,remark } = ctx.request.body
        const result = await EnterService.create(name,number,volume,categoryId,stashId,remark)
        await ItemService.create(name,number,volume,categoryId,stashId)
        ctx.body = result 
    }
    async list(ctx,next) {
        const page = ctx.query.page || 1
        const pageSize = ctx.query.pageSize || 10
        const {totalCount} = await EnterService.getListCount()
        const offset = (page - 1) * pageSize

        const items = await EnterService.getList(pageSize,offset)

        ctx.body = {
            totalCount,
            items
        }
    }
    async remove(ctx,next) {
        const { id } = ctx.query
        const result = await EnterService.remove(id)
        ctx.body = result
    }
}

module.exports = new EnterController()